import {defineConfig} from "vite";
import vue from "@vitejs/plugin-vue";
import dts from "vite-plugin-dts";
import libCss from "vite-plugin-libcss";
import path, {resolve} from "path";

export default defineConfig({
  base: '/',
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  plugins: [
    vue(),
    libCss(),
    dts({
      include: ["./src/packages/**/*.{vue,ts,css,js}"],
    }),
  ],
  // 打包配置
  build: {
    outDir: "src/components/gantt",
    lib: {
      entry: {
        index: path.resolve(__dirname, "./src/packages/Gantt/index.js")
      },
      name: 'ywlGanttPlus',
      formats: ["es", "cjs"], // , "umd", "iife"
      // fileName: (format, entryName) => {
      //   return 'index.[ext]';
      // },
    },
    cssCodeSplit: true,
    rollupOptions: {
      external: ["vue"],
      output: {
        globals: {
          vue: "Vue",
        },
        entryFileNames: '[name].[format].js',
        chunkFileNames: 'chunks/[name].js',
        assetFileNames: (assetInfo) => {
          const ext = assetInfo.name.split('.').at(1);
          if (ext === 'css') {
            return '[name][extname]';
          }
          return 'assets/[name][extname]';
        }
      },
    },
  },
  css: {}
});
